<?php
class Avatar extends AppModel {
	public $name = 'Avatar';
	
	public $belongsTo = array(
		'User' => array(
			'className' => 'User',
			'foreignKey' => 'user_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	);

	public function getAllAvatars($userId){
		$this->recursive = -1;
		$avatars = $this->find('all', array('conditions' => array('Avatar.user_id' => $userId)));
		return $avatars;
		
	}
        public function getAvatar($userId, $width){
            $avatar = $this->find('first', array('conditions' => array('Avatar.user_id' => $userId, 'Avatar.width' => $width)));
            if(!empty ($avatar))
                return $avatar['Avatar']['url'];
            else
                return '/files/avatars/default_48.png';
        }
}
?>